package au.chao.utils;

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import javax.swing.JDialog;
import javax.swing.JFrame;

public class GraphUtility {

	public static void setExistOnClose(JFrame fr){
		fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public static void centerWindow(JFrame fr){
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	    GraphicsDevice gs = ge.getDefaultScreenDevice();
	    DisplayMode dm = gs.getDisplayMode();
	    int x = (dm.getWidth() - fr.getWidth())/2;
	    int y = (dm.getHeight() - fr.getHeight())/2;
	    fr.setLocation(x,y);
	}
	
	public static void centerWindow(JDialog dlog){
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	    GraphicsDevice gs = ge.getDefaultScreenDevice();
	    DisplayMode dm = gs.getDisplayMode();
	    int x = (dm.getWidth() - dlog.getWidth())/2;
	    int y = (dm.getHeight() - dlog.getHeight())/2;
	    dlog.setLocation(x,y);
	    
	}
	
}
